<?php
/**
 * 
 */
namespace app\home\controller\user;

use app\home\controller\Base;

class Api extends Base
{

	/**
	 * 大于当前会员等级的所有等级
	 * @return [type] [description]
	 */
	public function up_levels(){
		$memberInfo = $this->memberInfo;
		// 所有会员等级
		$allLevels = model('level')::levelData();
		// 当前会员等级
		$currentLevel = $memberInfo['level_id'];
		$currentScore = $allLevels[$currentLevel]['score'];
		$data = [];
		foreach($allLevels as $level):
			if($level['score']>$currentScore){
				$data[] = $level;
			}
		endforeach;
		return json(['code'=>1,'data'=>$data]);
	}

	/**
	 * 会员信息接口
	 * @return [type] [description]
	 */
	public function info(){
		$params = $this->request->param();
		$field = isset($params['field'])?$params['field']:'';
		// 允许查询的字段
		$fields = [
			'mid',
			'status',
			'type',
			'mname',
			'phone',
			'create_time',
			'level_id',
			'area',
			'inviter_id',
			'seter_id',
			'agent_id',
			'agent_type_id',
			'is_agent',
			'p_agent',
			'is_phone_checked'
			];
		$model = model('member');
		if(!$field||!in_array($field,$fields)){
			$data = $model -> getOneDataById(UID,$fields);
		}else{
			$data = $model -> getOneDataById(UID,[$field]);
		}
		return json($data);
	}

	public function mail_out(){
		$params = $this->request->param();
		$where = $params;
		// 去除空值参数
		$where = filterArrEmptyItem($where);
		// 解析查询条件
		$where = parseWhere($where);
		$where['uid'] = UID;

		$data = model('mail')->getPageDatas($where);
		$data['code']=1;
		return json($data);
	}

	public function mail_in(){
		$params = $this->request->param();
		$where = $params;
		// 去除空值参数
		$where = filterArrEmptyItem($where);
		// 解析查询条件
		$where = parseWhere($where);
		$where['target'] = UID;

		$data = model('mail')->getPageDatas($where);
		$data['code']=1;
		return json($data);

	}

	public function mail_detail(){
		$params = $this->request->param();
		$id = $params['id'];
		$uid = UID;

		$model = model('mail');
		$data = $model->getOneSubject($id);
		if($data['uid']!=$uid&&$data['target']!=$uid){
			return json(['code'=>0,'msg'=>'权限不足']);
		}
		return json($data);
	}

}